import React from 'react';
import useAmis from '@/uses/useAmis';
import { createResourceCrudTable, makeCommonApi, makeCreateButton, makeDrawerButton } from '@/utils/amisUtils';

export default () => {
  const json = createResourceCrudTable({
    resourceName: 'users',
    detailColumns: [{
      "type": "input-text",
      "name": "name",
      "label": "用户名"
    },
      {
        "type": "input-text",
        "name": "nickname",
        "label": "昵称"
      },
      {
        "name": "isEnable",
        "type": "switch",
        "label": "是否启用",
      }],
    itemColumns:[
      {
        "name": "nickname",
        "label": "昵称",
        "sortable": true,
        "searchable": {
          "type": "input-text",
          "placeholder": "请输入",
          "mode": "horizontal"
        }
      },
      {
        "name": "name",
        "label": "用户名",
        "sortable": true,
        "searchable": {
          "type": "input-text",
          "placeholder": "请输入",
          "mode": "horizontal"
        }
      },
    ],
    actionBtnList: [
      makeDrawerButton(
        {
          btnText: '重置密码',
          detailApi: null,
          updateApi: makeCommonApi('/api/v1/users/resetPassword'),
          detailColumns:[
            {
              "type": "hidden",
              "name": "id",
              "value": "${id}"
            },
            {
              "type": "input-password",
              "name": "password",
              "label": "密码"
            },
          ]
        }
      ),
    ]
  });

  const AmisComponent = useAmis({
    "type": "page",
    "body": [
      json
    ]
  });

  return (
    <div>
      <AmisComponent/>
    </div>
  )
}